<template>
  <div class="permission-container">
    <div class="app-container">
      <!-- 表格 -->
      <el-card>

        <el-tabs>
            <el-table row-key="id" :data="list" border>
              <el-table-column label="序号" prop="name" >
                <template #default="{ row }">
                  {{ row.id }}
                </template>
              </el-table-column>
              <el-table-column prop="userId" label="用户id" />
         <el-table-column prop="num" label="订单号" />
         <el-table-column prop="amount" label="订单金额" />
         <el-table-column prop="paymentStatus" label="付款状态"   width="90"/>
         <el-table-column prop="status" label="状态"   />
         <el-table-column prop="createTime" label="订单创建时间" width="200"/>
         <el-table-column prop="updateTime" label="订单修改时间" width="200"/>
         <el-table-column prop="country"  label="国家" width="90"/>
         <el-table-column prop="postCode" label="邮编" />
         <el-table-column prop="packingTime" label="打包时间" width="300"/>
         <el-table-column prop="deliveryTime" label="出仓时间" width="300"/>
         <el-table-column prop="receiver" label="收件人" width="90"/>
         <el-table-column prop="receiverAddress" label="收件人地址" width="490"/>
         <el-table-column prop="weight" label="重量" width="90"/>
         <el-table-column prop="paymentType" label="支付类型" />
         <el-table-column prop="packageType" label="包裹类型" />
         <el-table-column prop="depositoryId" label="仓库id" width="90"/>
         <el-table-column prop="shippingCompanyId" label="出货公司id" width="120"/>
         <el-table-column prop="detailsId" label="费用明细id" width="120"/>
         <el-table-column prop="outTradeNo" label="微信支付订单号" width="120"/>
         <el-table-column prop="text"  fixed="right" label="操作" width="260">
          <template slot-scope="scope" width="222">
           
            <el-button size="small" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
          </template>

              </el-table-column>
            </el-table>
        
        </el-tabs>
      </el-card>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
      >
        <span>确定删除吗？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="deleteComfirm">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 弹框 -->
      <el-dialog :title="showTitle" :visible="showDialog" @close="closeDialog">
        <el-form v-loading="loading" label-width="130px">
           <el-form-item label="国际订单id" prop="id" >
            <el-input v-model="formData.userId" placeholder="请输入"  />  </el-form-item>

          <el-form-item label="用户表" prop="userid" >
            <el-input v-model="formData.userid" placeholder="请输入"  />
          </el-form-item>
          <el-form-item label="运单号" prop="amount">
            <el-input v-model="formData.amount" placeholder="请输入" />
          </el-form-item>

          <el-form-item label="付款状态" prop="paymentStatus">
            <el-input v-model="formData.paymentStatus" placeholder="请输入" />
          </el-form-item>

          <el-form-item label="包裹类型" prop="packageType">
            <el-input v-model="formData.packageType" placeholder="请输入" />
          </el-form-item>

          <el-form-item label="状态" prop="status">
            <el-input v-model="formData.status" placeholder="请输入" />
          </el-form-item>

           <el-form-item label="创建时间" prop="createTime">
            <el-date-picker
             v-model="formData.createTime"
             type="datetime"
             placeholder="请选择">
            </el-date-picker>
             </el-form-item>
             

            <el-form-item label="订单修改时间" prop="updateTime">
            <el-date-picker
             v-model="formData.updateTime"
             type="datetime"
             placeholder="请选择">
            </el-date-picker>
             </el-form-item>


          <el-form-item label="国家" prop="country">
            <el-input v-model="formData.country" placeholder="请输入" />
            </el-form-item>

            <el-form-item label="邮编" prop="postCode">
            <el-input v-model="formData.postCode" placeholder="请输入" />
             </el-form-item>

             <el-form-item label="打包时间" prop="packingTime">
            <el-date-picker
             v-model="formData.packingTime"
             type="datetime"
             placeholder="请选择">
            </el-date-picker>
             </el-form-item>
             

            <el-form-item label="出仓时间" prop="deliveryTime">
            <el-date-picker
             v-model="formData.deliveryTime"
             type="datetime"
             placeholder="请选择">
            </el-date-picker>
             </el-form-item>


            <el-form-item label="收件人姓名" prop="receiver">
            <el-input v-model="formData.receiver" placeholder="请输入" />
            </el-form-item>

           
            <el-form-item label="收件人地址" prop="receiverAddress">
            <el-input v-model="formData.receiverAddress" placeholder="请输入" /> </el-form-item>

            <el-form-item label="重量" prop="weight">
            <el-input v-model="formData.weight" placeholder="请输入" /> </el-form-item>

            <el-form-item label="支付类型" prop="paymentType">
            <el-input v-model="formData.paymentType" placeholder="请输入" /> </el-form-item>

            <el-form-item label="仓库" prop="depositoryId">
            <el-input v-model="formData.depositoryId" placeholder="请输入" /> </el-form-item>

            <el-form-item label="出货公司" prop="shippingCompanyId">
            <el-input v-model="formData.shippingCompanyId" placeholder="请输入" /> </el-form-item>

            <el-form-item label="费用明细表" prop="detailsId">
            <el-input v-model="formData.detailsId" placeholder="请输入" /> </el-form-item>

            <el-form-item label="微信支付订单号" prop="outTradeNo">
            <el-input v-model="formData.outTradeNo" placeholder="请输入" /> </el-form-item>

          
          
        </el-form>

        <template #footer>
          <div style="text-align: right;">
            <el-button @click="closeDialog">取消</el-button>
            <el-button type="primary" @click="clickSubmit">确认</el-button>
          </div>
        </template>
      </el-dialog>

    </div>

    <!-- 分页 -->
    <div align="center">
      <el-pagination
        :current-page.sync="currentPage"
        layout="prev, pager, next, jumper"
        :total="list.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import {SelectAll,update,deleteById} from '@/api/country'
export default {
  data() {
    return {
        // 时间
        deliveryTime:'',
        packingTime:'',
      // 是否是大包裹 单选框
       radio: '1',

      dialogVisible: false,
      // 分页数据
      currentPage: 3,
      list: [],
      pageParam:{ // 分页参数对象
      page:'',
      num: ''
      },
      showDialog: false,
      formData: {
        // enVisible: '0', // 0不开启, 1开启 (注意: 不是布尔值, 所以将来需要处理switch)
        username: '', // 名称
        password:''
      },
      loading: false,
      permissionData: [] // 存放用于展示的权限列表数据 (树形结构)
    }
  },
  computed: {
    showTitle() {
      if (this.formData.id) {
        return '编辑'
      }
    }
  },
  mounted() {
    console.log('进入页面的钩子函数')
    this.getPermissionList()
  },
  methods: {
     async getPermissionList() {
      let data = await SelectAll(this.pageParam)
      console.log('请求响应结果', data)
      this.list = data.list;
      this.dataTotal = data.total;
    },
    clickAdd(type, pid) {
      this.showDialog = true
      // 点击显示弹框时, 立刻记录type, pid
      // this.formData.type = type
      // this.formData.pid = pid
    },
    closeDialog() {
      this.showDialog = false
    
    },
    // 点击弹框的确认按钮
    async clickSubmit() {
     
      if (this.formData.id) {
        // 编辑操作
        const {postalcode,...formData} = this.formData
        await update(formData)
      } 
      this.showDialog = false
      this.$message.success('操作成功')
      this.getPermissionList()
    },
    // 删除功能
    handleDelete(id) {
      this.deleteId = id
      this.dialogVisible = true
    },
    async deleteComfirm() {
      this.dialogVisible = false
      await deleteById({
        id: this.deleteId
      })
      this.$message({
        message: '删除成功',
        type: 'success'
      })
      this.getPermissionList()
    },
    handleEdit(row){
      console.log(row)
      // const {postalCode,...formData} = row
      // formData.postalcode = postalCode
      this.formData = row;
      this.formData.postalcode = row.postalCode
      this.showDialog = true
    },
    // 点击查看编辑按钮, 显示弹框
    clickEdit(id) {
      // 显示弹框
      this.showDialog = true
      this.loading = true
      // 发送请求, 获取数据, 进行回显
      // const { data } = await reqGetPermissionDetail(id)
      // this.formData = data

      this.loading = false
    },

    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
    }
  }
}
</script>

<style>

</style>

